﻿using PmSoft;
using PmSoft.Utilities;

namespace AppWebApi.Services;

[UseDI(ServiceLifetime.Scoped)]
public class CommonService
{
    public CommonService() { }

    /// <summary>
    /// 获取随机人脸动作
    /// </summary>
    /// <param name="actionCount"></param>
    /// <returns></returns>
    public int[] GetRandFaceActions(int actionCount = 4)
    {
        List<int> selActions;
        var actions = new int[actionCount];
        int lastAction = 0;
        int middleNumber = (int)(actionCount / 2.0);
        for (int i = 0; i < actionCount; i++)
        {
            if (i == middleNumber)//中间插入眨眼
            {
                actions[i] = 5;
                continue;
            }
            selActions = new List<int> { 1, 2, 3, 4 };
            if (lastAction > 0)
                selActions.Remove(lastAction);
            int index = Rand.Next(0, selActions.Count);
            actions[i] = selActions[index];
            lastAction = actions[i];
        }
        return actions;
    }
}
